"""6.5 【上下文类】Context 大模型sampling服务端开发"""
from mcp import SamplingMessage
from mcp.server.fastmcp import FastMCP,Context
from mcp.types import TextContent

#创建mcp实例
mcp = FastMCP("Context with sampling MCP Server")

@mcp.tool()
async def sampling_tool(ctx:Context):
    """
    大模型sampling服务端开发
    :param ctx: 上下文类
    :return: 处理完成
    """
    response = await ctx.session.create_message(
        messages=[
          SamplingMessage(
              role="user",
              content = TextContent(
                  text="帮我编写一个小学放假通知的文章，字数在100-200字之间。",
                  type="text",
              )
          )
        ],
            max_tokens=1024
    )
    #打印response
    print("response:",response)
    return "大模型sampling回调完成"



if __name__ == '__main__':
    print("MCP Server is running...")
    mcp.run(transport='sse')